/*
 *  switch.h
 *  Author: Jonatan Schroeder
 */

#ifndef _SWITCH_H_
#define _SWITCH_H_

#include "capacity.h"

typedef struct switch_state_p1 {
  
  unsigned int* switch_table;

} switch_state_p1;

typedef struct switch_state_p2 {
  
  // TODO Add the members needed for part 2 here
  
  int remove_me; // Field added so code compiles, may be removed.
} switch_state_p2;

typedef struct switch_state_p3 {
  
  // TODO Add the members needed for part 3 here
  
  int remove_me; // Field added so code compiles, may be removed.
} switch_state_p3;

typedef union switch_state {
  switch_state_p1 p1;
  switch_state_p2 p2;
  switch_state_p3 p3;
} switch_state;

void initialize_switch(switch_state *state);
void forward_frame(switch_state *state, unsigned int port,
                   unsigned int source_addr, unsigned int dest_addr,
                   unsigned int frame_id);
void process_tick(switch_state *state);
void print_switch_state(switch_state *state);
void destroy_switch(switch_state *state);
void find_port(switch_state_p1 *p1_state, unsigned int port);


#define ADDRESS_FORMAT "%04x"
#define FRAME_ID_FORMAT "%03u"
#define PORT_FORMAT "P%u"

#endif
